package login

import (
	"beegoProject01/utils"
	"github.com/astaxie/beego"
)

type LoginController struct {
	beego.Controller
}

func (c *LoginController) Get() {

	// 引入 utils/GetCaptcha
	id, base64, err := utils.GetCaptcha()
	if err != nil {
		return
	}

	// 传入
	c.Data["captcha"] = utils.Captcha{Id: id, BS64: base64}
	c.TplName = "login/login.html"
}

func (c *LoginController) ChangeCaptcha() {
	message := map[string]interface{}{}
	id, base64, err := utils.GetCaptcha()
	if err != nil {
		message["msg"] = "生成验证码失败"
		//增加code正常和错误返回
		message["Code"] = 404
		c.Data["json"] = message
	} else {
		c.Data["json"] = utils.Captcha{Id: id, BS64: base64, Code: 200}
	}
	c.ServeJSON()
}
